package adminAction;

import dao.BookDao;
import po.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

@WebServlet(urlPatterns = "/admin/adminAction/ProductEditServlet")
public class ProductEditServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String isbn = req.getParameter("isbn");
        Double price = Double.parseDouble(req.getParameter("price"));
        Book book = new Book();
        book.setIsbn(isbn);
        book.setPrice(price);
        BookDao bookDao = new BookDao();
        Integer row = bookDao.updatePriceById(book);
        Writer writer = null;
        try {
            writer = resp.getWriter();
            if (row>0){
                writer.write("yes");
            }else {
                writer.write("no");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
